#include <StructDescr.h>

void Model::on_btnAddSub_clicked()
{
	addItem(CounterToCaption(), false);
	statusbar->showMessage(QString("An SubItem created"),1000);
}

void Model::on_btnAdd_clicked()
{
	addItem(CounterToCaption(), true);
	statusbar->showMessage(QString("An Item created"),1000);
}

void Model::on_btnCorrect_clicked()
{
	QString  mes;
	switch(showItemChangeDialog())
	{
	case -1: mes = QString("No Items selected!"); break;
	case  1: mes = QString("Item's data changed"); break;
	case  0: mes = QString("Canceled"); break;
	}
	statusbar->showMessage(mes,1000);
}

void Model::on_btnNew_clicked()
{
	Count = 0;
	statusbar->showMessage(QString("New tree created!"),5000);
}

void Model::on_btnDelete_clicked()
{
	QVariant delItemCount = Delete(treeWidget->currentItem());
	statusbar->showMessage(QString(delItemCount.toString() + " elements deleted"), 5000);
}

void Model::on_actionSave_triggered()
{
	QString saveFileName;
	if(fileSaveDialog(saveFileName))
	{
		if(saveTree(saveFileName))
			statusbar->showMessage(QString("Structure saved to file" + saveFileName) ,2000);
		else statusbar->showMessage(QString("Save failed!"),2000);
	}
}

void Model::on_actionLoad_triggered()
{
	QString openFileName;
	if(fileOpenDialog(openFileName))
	{
		if(loadTree(openFileName))
			statusbar->showMessage(QString("Structure loaded from file" + openFileName) ,2000);
		else statusbar->showMessage(QString("Load failed!"),2000);
	}
}

void Model::on_actionExit_triggered()
{
	emit close();
}